/**
 * Solution.java
 */
package dateconversion;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author prakash
 *
 */
public class Solution {

	public static void main(String args[]) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int noOfTestCase = Integer.parseInt(br.readLine());

		Solution solution = new Solution();
		while (noOfTestCase-- > 0) {
			System.out.println(solution.convert(br.readLine()));
		}
	}

	public String convert(String dateString) {
		if (dateString == null) {
			throw new RuntimeException("Invalid data.");
		}
		StringBuilder convertedString = new StringBuilder();
		String[] splitString = dateString.split(" ");
		if (null != splitString && splitString.length == 3) {
			convertedString.append(splitString[2]).append("-");
			convertedString.append(YEAR.getFrom(splitString[1]).getValue()).append("-");
			convertedString.append(getNumbers(splitString[0]));
		} else {
			throw new RuntimeException("Invalid data.");
		}
		return convertedString.toString();
	}

	private String getNumbers(String literal) {
		String number = literal.replaceAll("\\D+", "");
		return number.length() == 1 ? "0" + number : number;

	}

	private enum YEAR {
		Jan("01"), Feb("02"), Mar("03"), Apr("04"), May("05"), Jun("06"), Jul("07"), Aug("08"), Sep("09"), Oct("10"), Nov(
				"11"), Dec("12");
		String value;

		YEAR(String value) {
			this.value = value;
		}

		public String getValue() {
			return value;
		}

		public static YEAR getFrom(String name) {
			for (YEAR aYear : values()) {
				if (aYear.toString().equals(name)) {
					return aYear;
				}
			}
			throw new RuntimeException("Invalid enum type.");
		}
	}
}
